package com.jbm.jbmsupplier.activity;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.jbm.core.iface.IAcross;
import com.jbm.jbmsupplier.R;
import com.jbm.jbmsupplier.net.NetIntent;
import com.jbm.jbmsupplier.shared.SharedPreferActivity;
import com.jbm.jbmsupplier.utlis.ExitActivity;
import com.jbm.jbmsupplier.view.DoubleButtonDialog;
import com.jbm.jbmsupplier.zp.service.MyService;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by 家帮忙 on 2017/4/10.
 */

public class UserSet extends AllActivityApp {

    @InjectView(R.id.teleft)
    TextView teleft;
    @InjectView(R.id.tetitle)
    TextView tetitle;
    @InjectView(R.id.userpwd)
    TextView userpwd;
    @InjectView(R.id.srmingxi)
    TextView srmingxi;
    @InjectView(R.id.exitlogin)
    TextView exitlogin;
    private final int EXITLOGIN=0002;

    @Override
    public int setContentView() {
        return R.layout.lz_userset;
    }

    @Override
    public void initIalizeView() {
        ExitActivity.getInstance().addActivity(this);
        ButterKnife.inject(this);
        tetitle.setText("设置");

    }


    @OnClick({R.id.teleft, R.id.userpwd, R.id.srmingxi,R.id.exitlogin})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.teleft:
                finish();
                break;
            case R.id.userpwd:
                startActivity(new Intent(this, AmendPwass.class));
                this.finish();
                break;
            case R.id.srmingxi:
                startActivity(new Intent(this, IncomeActivity.class));
                break;
            case R.id.exitlogin:
                final DoubleButtonDialog dialog = new DoubleButtonDialog(this,"是否退出当前用户");
                dialog.setNoText("取消");
                dialog.setTetle_message("");
                dialog.setisVisibilitymess();
                dialog.getokbtn().setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {//确定
                        new SharedPreferActivity(UserSet.this).setExitLogin();
                        stopService(new Intent( UserSet.this,MyService.class));
//                        ExitActivity.getInstance().exitActivity();
                        startActivity(new Intent(UserSet.this, LoginActivity.class));
                        new Thread(new Runnable() {
                            @Override
                            public void run() {
                                NetIntent netDeceVersion=new NetIntent(handler);
                                netDeceVersion.setExit(EXITLOGIN);
                            }
                        }).start();

                        dialog.dismiss();
                    }
                });
                dialog.getnobtn().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        dialog.dismiss();
                    }
                });



                break;
        }
    }
Handler handler=new Handler(){
    @Override
    public void handleMessage(Message msg) {
        super.handleMessage(msg);
        switch (msg.what){
            case EXITLOGIN:
                IAcross exit=(IAcross)msg.obj;
                if (exit.m_code==200){
                   Log.e("main","退出成功");
                }else{
                    Log.e("main","退出成功"+exit.m_info);
                }

            break;
        }
    }
};

}
